package com.cookiesoft.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cookiesoft.common.annotation.Log;
import com.cookiesoft.common.core.controller.BaseController;
import com.cookiesoft.common.core.domain.AjaxResult;
import com.cookiesoft.common.enums.BusinessType;
import com.cookiesoft.product.domain.ZhenProducts;
import com.cookiesoft.product.service.IZhenProductsService;
import com.cookiesoft.common.utils.poi.ExcelUtil;
import com.cookiesoft.common.core.page.TableDataInfo;

/**
 * 商品，存储商品信息及库存Controller
 *
 * @author anc
 * @date 2024-11-05
 */
@CrossOrigin
@RestController
@RequestMapping("/product/goods" )
public class ZhenProductsController extends BaseController {
    @Autowired
    private IZhenProductsService zhenProductsService;

/**
 * 查询商品，存储商品信息及库存列表
 */
@PreAuthorize("@ss.hasPermi('product:goods:list')" )
@GetMapping("/list" )
    public TableDataInfo list(ZhenProducts zhenProducts) {
        startPage();
        List<ZhenProducts> list = zhenProductsService.selectZhenProductsList(zhenProducts);
        return getDataTable(list);
    }

    /**
     * 导出商品，存储商品信息及库存列表
     */
    @PreAuthorize("@ss.hasPermi('product:goods:export')" )
    @Log(title = "商品，存储商品信息及库存" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ZhenProducts zhenProducts) {
        List<ZhenProducts> list = zhenProductsService.selectZhenProductsList(zhenProducts);
        ExcelUtil<ZhenProducts> util = new ExcelUtil<ZhenProducts>(ZhenProducts. class);
        util.exportExcel(response, list, "商品，存储商品信息及库存数据" );
    }

    /**
     * 获取商品，存储商品信息及库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:goods:query')" )
    @GetMapping(value = "/{productId}" )
    public AjaxResult getInfo(@PathVariable("productId" ) Long productId) {
        return success(zhenProductsService.selectZhenProductsByProductId(productId));
    }

    /**
     * 新增商品，存储商品信息及库存
     */
    @PreAuthorize("@ss.hasPermi('product:goods:add')" )
    @Log(title = "商品，存储商品信息及库存" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhenProducts zhenProducts) {
        return toAjax(zhenProductsService.insertZhenProducts(zhenProducts));
    }

    /**
     * 修改商品，存储商品信息及库存
     */
    @PreAuthorize("@ss.hasPermi('product:goods:edit')" )
    @Log(title = "商品，存储商品信息及库存" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhenProducts zhenProducts) {
        return toAjax(zhenProductsService.updateZhenProducts(zhenProducts));
    }

    /**
     * 删除商品，存储商品信息及库存
     */
    @PreAuthorize("@ss.hasPermi('product:goods:remove')" )
    @Log(title = "商品，存储商品信息及库存" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{productIds}" )
    public AjaxResult remove(@PathVariable Long[] productIds) {
        return toAjax(zhenProductsService.deleteZhenProductsByProductIds(productIds));
    }
}
